package sd.czw.com.mmgapp.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import sd.czw.com.mmgapp.Contants;
import sd.czw.com.mmgapp.R;
import sd.czw.com.mmgapp.activity.GoodsDeatilActivity;
import sd.czw.com.mmgapp.model.shouyebean.HomeGoodsInfo;

/**
 * Created by czw
 * desc 描述：
 * on 2017/7/6.
 */
public class SyRvAdapter extends RecyclerView.Adapter<SyRvAdapter.MyViewHolder> {

    private Context context;
    private List<HomeGoodsInfo.ErrmsgBean> datas;
    private int width;

    public SyRvAdapter(Context context, List<HomeGoodsInfo.ErrmsgBean> datas,int width) {
        this.context = context;
        this.datas = datas;
        this.width = width;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.syrv_child, parent, false));
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        if (datas != null){
            Glide.with(context).load(Contants.BASE_URL+datas.get(position).getGoods_img()).placeholder(new ColorDrawable(Color.parseColor("#f5f5f5"))).into(holder.layoutGvChildImg);
            holder.layoutGvChildImg.setLayoutParams(new LinearLayout.LayoutParams((int)(width/Double.valueOf(2)),(int)(width/Double.valueOf(2))));
            holder.layoutGvChildTvtitle.setText(datas.get(position).getGoods_name());
            holder.layoutGvChildTvprice1.setText("¥"+datas.get(position).getShop_price());
            holder.layoutGvChildTvprice2.setText("¥"+datas.get(position).getMarket_price());
            holder.layoutGvChildTvprice2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            holder.layoutGvChildTvnum.setText(datas.get(position).getClick_count()+"人浏览");
            holder.layoutGvChildCount2.setText(""+datas.get(position).getSales_count());

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context,GoodsDeatilActivity.class);
                    intent.putExtra("goods_id",datas.get(position).getGoods_id());
                    context.startActivity(intent);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.layout_gv_child_img)
        ImageView layoutGvChildImg;
        @Bind(R.id.layout_gv_child_tvtitle)
        TextView layoutGvChildTvtitle;
        @Bind(R.id.layout_gv_child_tvprice1)
        TextView layoutGvChildTvprice1;
        @Bind(R.id.layout_gv_child_tvprice2)
        TextView layoutGvChildTvprice2;
        @Bind(R.id.layout_gv_child_count1)
        TextView layoutGvChildCount1;
        @Bind(R.id.layout_gv_child_count2)
        TextView layoutGvChildCount2;
        @Bind(R.id.layout_gv_child_tvnum)
        TextView layoutGvChildTvnum;
        @Bind(R.id.ll)
        LinearLayout ll;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
